package com.credithc.customers.manager.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.customers.base.ro.LoginFlowRo;
import com.credithc.customers.base.vo.LoginFlowVo;
import com.credithc.customers.manager.service.LoginFlowService;
import com.credithc.customers.manager.service.impl.AuthorizationServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title:
 * @Author: fby
 * @Date: 2020/03/24 09:56
 * @Description: com.credithc.customers.manager.controller
 * @Version: V1.0.0
 */
@RestController
@RequestMapping("/manager/yzt/v1")
public class CustomerUnifyLoginFlowController {
    @Autowired
    MessageFactory messageFactory;
    @Autowired
    LoginFlowService loginFlowService;
    @Autowired
    AuthorizationServiceImpl authorizationService;

    /**
     * @description: 登陆流水展示
     * @Author: fby
     * @Date: 2020/03/24 09:56
     * @return: com.credithc.baseserv.core.message.Message
     */
    @GetMapping("/loginFlow")
    public Message getloginFlow(@RequestHeader("token") String token, @PathParam("caller") String caller, HttpServletRequest request, @PathParam("requestNo") String requestNo, @PathParam("systemSign") String systemSign, @PathParam("subSystemSign") String subSystemSign, @PathParam("phone") String phone, @PathParam("status") Integer status, @PathParam("createTimeStart") String createTimeStart, @PathParam("createTimeEnd") String createTimeEnd, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        LoginFlowRo ro = new LoginFlowRo();
        ro.setRequestNo(requestNo);
        ro.setSystemSign(systemSign);
        ro.setSubSystemSign(subSystemSign);
        ro.setPhone(phone);
        ro.setStatus(status);
        ro.setCreateTimeStart(createTimeStart);
        ro.setCreateTimeEnd(createTimeEnd);
        ro.setPageNo(pageNo);
        ro.setPageSize(pageSize);
        if (StringUtils.isNotBlank(caller) && "TENANT".equals(caller)) {
            List<String> productCodes = authorizationService.authChannelRo(token,request);
            ro.setChannelNos(productCodes);
        }
        PageInfo<LoginFlowVo> list = loginFlowService.getLoginFlow(ro);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);

    }
}
